<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<style>

    table, th, td {
        border: 1px solid black;
        border-collapse: collapse;
    }

    th, td {
        padding: 5px;
    }
</style>
<body>

<h2>The XMLHttpRequest Object</h2>

<button type="button" onclick="loadDoc()">Get my CD collection</button>
<br><br>
<table id="demo"></table>

<script>
    function loadDoc() {
        const xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (this.readyState === 4 && this.status === 200) {
                myFunction(this);
            }
        };
        xhttp.open("GET", "cd_catatalog1.xml", true);
        xhttp.send();
    }

    function myFunction(xml) {
        let table = "<thead><tr><th>TITLE</th><th>ARTIST</th><th>ALBUM</th><th>COUNTRY</th><th>COMPANY</th><th>YEAR</th></tr></thead><tbody>";
        const x = xml.responseXML.getElementsByTagName("TRACK");
        for (let i = 0; i < x.length; i++)
            table += "<tr><td>" +
                x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue +
                "</td><td>" +
                x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue +
                "</td><td>" +
                x[i].getElementsByTagName("ALBUM")[0].childNodes[0].nodeValue +
                "</td><td>" +
                x[i].getElementsByTagName("COUNTRY")[0].childNodes[0].nodeValue +
                "</td><td>" +
                x[i].getElementsByTagName("COMPANY")[0].childNodes[0].nodeValue +
                "</td><td>" +
                x[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue +
                "</td></tr>";
        document.getElementById("demo").innerHTML = "<table class='table table-bordered table-hover' >" + table + "</tbody></table>";
    }
</script>

</body>
</html>

